IF EXISTS ( SELECT  *
            FROM    dbo.sysobjects
            WHERE   id = OBJECT_ID(N'[CGO_CharitySave]')
                    AND OBJECTPROPERTY(id, N'IsProcedure') = 1 ) 
  DROP PROCEDURE CGO_CharitySave
GO

SET QUOTED_IDENTIFIER ON
SET ANSI_NULLS ON
GO



CREATE PROCEDURE dbo.CGO_CharitySave
  @CharityID INT ,
  @PortalID INT ,
  @UserID INT ,
  @Status INT,
  @Name NVARCHAR(90),
  @Description NTEXT,
  @Contact NVARCHAR(50),
  @WebSite NVARCHAR(255),
  @Email NVARCHAR(255),
  @Telephone NVARCHAR(30),
  @Fax NVARCHAR(30),  
  @Address NVARCHAR(255),
  @Category NVARCHAR(50),
  @ImageURL NVARCHAR(100),
  @ImageType VARCHAR(1),
  @ImageWidth INT,
  @ImageHeight INT,
  @ImageDisplay BIT
AS    
  IF @Contact = N'' 
    SET @Contact = NULL
    
  IF @WebSite = N'' 
    SET @WebSite = NULL
  
  IF @Email = N'' 
    SET @Email = NULL
  
  IF @Telephone = N''
    SET @Telephone = NULL
    
  IF @Fax = N''  
    SET @Fax = NULL
    
  IF @Address = N'' 
    SET @Address = NULL
  
  IF @Category = N'' 
    SET @Category = NULL
    
  IF @ImageURL = N'' 
    SET @ImageURL = NULL
    
  IF @ImageType = N'' 
    SET @ImageType = NULL   
    
  IF @ImageDisplay IS NULL
    SET @ImageDisplay = 0
              
  IF @CharityID IS NULL OR @CharityID =-1 OR @CharityID = 0
  BEGIN
  	INSERT INTO dbo.CGO_Charity
  	        ( PortalID ,  	          
  	          Name ,
  	          Description ,
  	          Contact ,
  	          WebSite ,
  	          Email ,
  	          Telephone,
  	          Fax,
  	          Address ,
  	          Category ,
  	          ImageURL,
  	          ImageType,
  	          ImageHeight,
  	          ImageWidth,
  	          Status,
  	          ImageDisplay,
  	          CreatedByID,
  	          CreatedDate,
  	          LastUpdatedID,
  	          LastUpdateDate
  	        )
  	VALUES  ( @PortalID , -- PortalID - int  	          
  	          @Name , -- Name - nvarchar(90)
  	          @Description , -- Description - nvarchar(500)
  	          @Contact , -- Contact - nvarchar(50)
  	          @WebSite , -- WebSite - nvarchar(255)  	          
  	          @Email , -- Email - nvarchar(255)
  	          @Telephone, --Telephone - nvarchar(30)
  	          @Fax, -- Fax - nvarchar(30)
  	          @Address , -- Address - nvarchar(255)
  	          @Category , -- Category - nvarchar(50)
  	          @ImageURL , 
  	          @ImageType, 
  	          @ImageHeight, 
  	          @ImageWidth,         
  	          @Status, -- Status - int
  	          @ImageDisplay,
  	          @UserID, 
  	          GETDATE(),
  	          -1,
  	          GETDATE()   	          
  	        )
  END
  ELSE
  BEGIN
   UPDATE dbo.CGO_Charity
   SET    Name = @Name ,
          Description = @Description ,
          Contact = @Contact ,
          WebSite = @WebSite ,
          Email = @Email ,
          Telephone = @Telephone,
          Fax = @Fax,
          Address = @Address ,
          Category = @Category ,
          ImageURL = @ImageURL,
          ImageType = @ImageType,
          ImageHeight = @ImageHeight,
          ImageWidth = @ImageWidth,          
          Status = @Status ,
          ImageDisplay = @ImageDisplay,
          LastUpdatedID = @UserID,
          LastUpdateDate = GETDATE()          
   WHERE  CharityID = @CharityID
          AND PortalID = @PortalID
  	
  END
GO
